// 1.引入公用样式表
require("../../assets/css/index.less");
// require("../../assets/fonts/iconfont.css")

// 2.引入当前样式表
require("./user.less");

// 引入插件

// 3.引入公用js模块
let dom = require("../../utils/dom.js");
let https = require("../../utils/https.js");
let local = require("../../utils/local.js");

// 3. 引入轮播图
import Swiper from "../../assets/lib/swiper/swiper-bundle.min.js";
import "../../assets/lib/swiper/swiper-bundle.min.css";

// 判断是否有登录
dom.isToken();
dom.ready(function () {
	// dom.goTo('#toPersonal', 'personal');
	// dom.$("#toPersonal").addEventListener("click", function () {
	// 	console.log(1111);
	// 	location.href = `personal.html`;
	// });
	// 渲染底部Tab
	dom.render(3);
	dom.goTo('#toPersonal', 'personal');
	dom.goTo('#toSocial', 'social');
	dom.goTo('#toSports', 'echartsData');
	dom.goTo('#toBadge', 'badge');
	new Swiper(".swiper", {
		autoplay: true, //可选选项，自动滑动
		loop: true,
		pagination: {
			el: ".swiper-pagination",
		},
	});

	dom.getUserInfo();
	dom.isClockIn();

	// 给打卡按钮绑定点击事件
	dom.$("#punchBtn").addEventListener("click", function () {
		https.post("/api/user/clockIn", {}, (res) => {
			if (res.errno == 0) {
				alert("打卡成功");
				isClockIn();
			} else {
				alert(res.message);
			}
		});
	});

	// 获取个人信息功能
	function getUserInfo() {
		https.get('/api/user/info', res => {
			if (res.errno == 0) {
				let { imgUrl, nickName, sign } = res.data;
				dom.$('#avatar').src = https.BASE_URL + imgUrl;
				dom.$('#userName').innerHTML = nickName;
				dom.$('#introduce').innerHTML = sign;
				local.set('user', res.data)
			}
		})
	}
	getUserInfo()









});
